////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011-2012 www.iflytek.com. All Rights Reserved.
//  This software for customer relationship management system, developed by Iflytek_ZY team.
//  Software code and design for the team, copy rights reserved.
////////////////////////////////////////////////////////////////////////////////

package com.iflytek.ci.main.controller;

import java.io.UnsupportedEncodingException;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * .
 * </p>d
 *
 * @author poplar.yfyang
 * @version 1.0 2012-10-25 10:29 PM
 * @since JDK 1.5
 */
@Controller
public class LoginController extends BaseController {
	/** 序列化ID */
	private static final long serialVersionUID = -5398967722052675469L;

	/**
	 * 跳转到登录页面
	 *
	 * @return 登录视图地址
	 */
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		return "login";
	}

	/**
	 * 登录失败处理
	 *
	 * @param userName 用户名
	 * @param model    ui 模型
	 * @return 登录视图页面地址
	 */
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName,
					   final Model model) {
		try {
			model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, new String(userName.getBytes(), "GB2312"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.addAttribute("login_value", "");
		model.addAttribute("error", "用户名或者密码错误");
		return "login";
	}
}
